package framework;

import javax.swing.JPanel;

/**
 * This class implements the SelfDrawCellInterface.
 * 
 */

public class SelfDrawCell implements SelfDrawCellInterface {
	// Cell that is being wrapped into selfdraw cell
	private CellInterface c;
	// All selfdraw cells share the same client-defined plugins
	private VisualizerPluginInterface vp;
	private AutomatonPluginInterface ap;

	/**
	 * Constructor that creates SelfDrawCell.
	 * 
	 * @param CellInterface c - the cell that will be transferred into a selfDrawCell
	 * @param VisualizerPluginInterface vp - the visualizer plugin
	 * @param AutomatonPluginInterface ap - the automaton plugin
	 */
	public SelfDrawCell(CellInterface c, VisualizerPluginInterface vp,
			AutomatonPluginInterface ap) {
		// Initialize fields
		this.c = c;
		this.vp = vp;
		this.ap = ap;
	}

	
	/**
	 * Returns the cell stored in this selfdraw cell.
	 * 
	 * @return CellInterface c - get the cell wrapped in the selfDrawCell
	 */
	@Override
	public CellInterface getCell() {
		return c;
	}

	/**
	 * Given an array of neighbors, updates the state of this selfDraw cell with
	 * respect to its neighbors using client-defined updateCell method in
	 * automaton plugin.
	 * 
	 * @param int[] csStates - the states of the neighbors
	 */
	public void updateCell(int[] csStates) {
		ap.updateCellState(c, csStates);
	}

	/**
	 * Given a panel to draw on, this method draws the visualization of this
	 * cell at the its corresponding position using the client-defined
	 * drawCell(Cell.getState(), Cell.getColNum(), Cell.getRowNum()) method in
	 * visualizer plugin.
	 * 
	 * @param JPanel pane - the panel on which each cell should be drawn on
	 */
	public void drawCell(JPanel pane) {
		vp.drawCell(pane, c.getState());
	}

}
